package com.example.controller;


import com.example.constant.sta;
import com.example.mapper.SampleMapper;
import com.example.pojo.PageResult;
import com.example.pojo.Result;
import com.example.pojo.VerifyResult;
import com.example.pojo.VerifyResultImg;
import com.example.service.VerifyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RequestMapping("/verify")
@RestController
public class VerifyController {

    @Autowired
    private VerifyService verifyService;

    /**
     * 获取验证结果 -GET http://localhost:8881/verify/result
     */
//    @GetMapping("/result")
//    public Result getVerifyResult() {
//        log.info("获取验证结果");
//        VerifyResult verifyResult=new VerifyResult();
//        verifyResult.setMsgType(sta.msgType);
//        verifyResult.setVerifyResult(sta.verifyResult);
//        verifyResult.setDefectName(sta.staDefectName);
//        verifyResult.setBrandName(sta.staBrandName);
//        verifyResult.setFileList(sta.fileList);
//        verifyResult.setMachineID(sta.machineID);
//
//        verifyService.completeVerifyResult(verifyResult);
//
//        log.info(String.valueOf(verifyResult));
//        return Result.success(verifyResult);
//    }
    /**
     * 获取最新的验证结果  --GET http://localhost:8881/verify/newest
     */
    @GetMapping("/newest")
    public Result getNewestVerifyResult() {
        log.info("获取最新的验证结果");
        VerifyResult verifyResult = verifyService.findNewest();
        //log.info(String.valueOf(verifyResult));
        return Result.success(verifyResult);
    }

    /**
     * 根据id获取验证结果细节  --GET http://localhost:8881/verify/detail?id=1
     */
    @GetMapping("/detail")
    public Result getVerifyResultDetail(Integer id) {
        log.info("根据id获取验证结果细节");
        List<VerifyResultImg> verifyResultImgList = verifyService.findByVerifyResultID(id);
        //log.info(String.valueOf(verifyResultImgList));
        return Result.success(verifyResultImgList);
    }

    /**
     * 分页查询验证结果  --GET http://localhost:8881/verify/page?page=1&pageSize=10
     */
    @GetMapping("/page")
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize){
        log.info("分页查询验证结果，当前页码为：{}，每页记录数：{}",page,pageSize);
        PageResult pageResult = verifyService.page(page, pageSize);
        return Result.success(pageResult);
    }

    /**
     * 获取所有不同machineID的最新验证结果  --GET http://localhost:8881/verify/allNewest
     */
    @GetMapping("/allNewest")
    public Result getAllNewestVerifyResult() {
        log.info("获取所有不同machineID的最新验证结果");
        List<VerifyResult> verifyResultList = verifyService.getAllNewest();
        //log.info(String.valueOf(verifyResultList));
        return Result.success(verifyResultList);
    }



}
